<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" id="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea id="content" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">日期：</label>
        <div class="layui-input-inline">
            <input type="text"  class="layui-input" id="date" placeholder="yyyy-mm-dd" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-block">
            <input type="text" id="writer" required  lay-verify="required" placeholder="请输入作者名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="tijiao" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="../layui/layui.js" charset="utf-8"></script>
<script src="../js/jquery.min.js"></script>
<script>
    layui.use('laydate', function() {
        let laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#date'
            ,trigger: 'click'
        });
    });
    $("#tijiao").click(function () {
        $.ajax({
            url: "/news/xinZeng",
            method: "post",
            contentType: "application/json",
            data: JSON.stringify({
                ntitle: $("#title").val(),
                ncontent: $("#content").val(),
                ndate: $("#date").val(),
                nwriter:$("#writer").val(),
                status:0
            }),
            success: function (res) {
                if (res.code == 200) {
                    layer.msg("添加成功");

                } else {
                    layer.msg("添加失败");
                }
                layer.close();


            }

        })
    });


</script>
</body>
</html>